/*
 * edb.h - EnCluster Base DB Client part interfaces
 * Clunix, glory@clunix.com, yjlee@clunix.com, 2001.7.18.
 * Clunix, cezanne@clunix.com, 2005.3
 *
 * $Id: edb.h,v 1.1.1.1.10.3 2008/05/28 01:42:21 cezanne Exp $
 *
 * Copyright (c) 2001-2005 by Clunix Inc. All Rights Reserved.
 */

#ifndef _EDB_H_
#define _EDB_H_

#include "ebc.h"
#include "libedb.h"

#define EDB_TIMEOUT		36000	/* msec */

#ifdef ECM_DEBUG

extern ecm_dbg_t	edb_dbg;

#define EDB_DBG_MESSAGE		0x0001
#define EDB_DBG_EDBD		0x0002
#define EDB_DBG_CLIENT		0x0004
#define EDB_DBG_SERVER		0x0008
#define EDB_DBG_UTILITY		0x0010
#define EDB_DBG_CNP		0x0020
#define EDB_DBG_CMD		0x0040

extern srt_t	ST_EDEXPR;

#define EDBDBG(dbgset, fmt, ...)	ECMDBG(edb_dbg, dbgset, fmt, ## __VA_ARGS__)

#else

#define EDBDBG(dbgset, fmt, ...)        do {} while(0)

#endif

#ifdef __cplusplus
extern "C" {
#endif

typedef struct {
	ECMBOOL		going_to_shutdown;
	ecm_thread_t	listener;
	ecm_ebc_t	ebc;
	ecm_cond_t	cond;
	ecm_hashtable_t	moncbs;
	ecm_uint32	n_active_cbs;
} edb_pathmon_t;

/* EDB client part data structure */
struct _edb_t {
	ecm_mutex_t	mutex;
	ECMBOOL		connected, is_master, session, master_mode;
	ebc_addr_t	dstaddr;
	char		*user;
	char		*passwd;	/* TODO: encryption needed */
	ecm_ebc_t	ebc;
	edb_pathmon_t	*pathmon;
	ecm_ptr_t	fileset;
};

edb_err_t edb_ecx(edb_t *e, const char *cmd, sr_t *sr_session, sr_t **psr_res);

sr_t *edb_exectx_to_sr(sr_exectx_t *pctx);

ECMBOOL edb_initialize(void);

edb_err_t edb_sreq(edb_t *e, int cmd_code, sr_t *sr_args, sr_t **psr_res);

void edb_add_all_pathmon(edb_t *e);
void edb_del_all_pathmon(edb_t *e);

void destroy_edb_files(edb_t *e);

#ifdef ECM_DEBUG

edb_err_t edb_dbgset(edb_t *e, const char *modname, const char *dbgset);

edb_err_t edb_mtrace_info(edb_t *e, sr_t **psr_res);
edb_err_t edb_mtrace_on(edb_t *e, int level);
edb_err_t edb_mtrace_off(edb_t *e);
edb_err_t edb_mtrace_clear(edb_t *e);
edb_err_t edb_mtrace_report(edb_t *e, sr_t **psr_res);

edb_err_t edb_treelock_info(edb_t *e, sr_t **psr_res);

#endif

#ifdef __cplusplus
}
#endif

#endif  /* _EDB_H_ */

